“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
“Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.”
---
title: "1ra Ronda ICPCovid - Perú"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
social: menu
theme: cosmo
self_contained: TRUE
fig_mobile: TRUE
---
```{r}
library(flexdashboard)
library(readr)
library(haven)
library(tidyr)
library(dplyr)
library(stringr)
library(skimr)
library(sf)
library(rmapshaper)
library(tidyverse)
library(viridis)
library(ggiraphExtra)
library(png)
library(grid)
library(ggplot2)
library(scales)
library(alluvial)
library(ggalluvial)
library(fmsb)
library(hrbrthemes)
library(ggwaffle)
library(waffle)
library(waffle)
library(extrafont)
library(tidyverse)
library(ggpubr)
library(plyr)
library(Hmisc)
library(Gmisc)
library(magrittr)
library(codebook)
library(future)
library(abd)
library(epitools)
library(magrittr)
library(qwraps2)
```
```{r}
data <- read.csv("../Output/ICPCovid_r1_0728.csv")
```
```{r, class.output="scroll-100", error=F, warning=F, echo=F, message=F,include=F}
shp <- st_read("../Data/shapefile_distr", stringsAsFactors = F)%>%
st_transform(4326) %>%
dplyr::select(reg = NOMBDEP,
prov = NOMBPROV,
distr = NOMBDIST)%>%
ms_simplify(keep=0.2)%>%
dplyr::mutate(distr =gsub("_", " ",gsub("-", " ", iconv(distr,
from="UTF-8",
to="ASCII//TRANSLIT"), fixed=TRUE), fixed=TRUE),
prov = iconv(prov,
from="UTF-8",
to="ASCII//TRANSLIT"),
reg = iconv(reg,
from="UTF-8",
to="ASCII//TRANSLIT")
) %>%
dplyr::mutate(distr = ifelse(distr=="HUAYA","HUALLA",
ifelse(distr=="MAZAMARI PANGOA","MAZAMARI",
ifelse(distr=="LARAOS" & prov=="HUAROCHIRI","SAN PEDRO DE LARAOS",distr))))
shp.nac <- st_read("../Data/Limite_departamental", stringsAsFactors = F)%>%
st_transform(4326) %>%
dplyr::select(reg = NOMBDEP)%>%
ms_simplify(keep=0.2)%>%
dplyr::mutate(reg = iconv(reg,
from="UTF-8",
to="ASCII//TRANSLIT")
)
shp.prov <- st_read("../Data/shapefile_prov", stringsAsFactors = F)%>%
st_transform(4326) %>%
dplyr::select(prov = PROVINCIA)%>%
ms_simplify(keep=0.2)%>%
dplyr::mutate(prov = iconv(prov,
from="UTF-8",
to="ASCII//TRANSLIT")
)
```
```{r config_lima, error=F, warning=F, echo=F, message=F}
my_breaks <- c(0, 100, 250, 500)
breaks_nac <- c(0, 50, 125, 250)
data.shp.lima <- merge(shp %>%
dplyr::filter(prov=="LIMA" | prov=="CALLAO"),
data %>%
dplyr::filter(reg=="LIMA"| reg=="CALLAO"), by=c("reg","distr"),all.x=T)
data.shp.nac <- merge(shp.nac %>%
select(reg),
data %>% filter(reg !="LIMA") %>%
select(reg), by=c("reg"),all=T)
shapefile_prov_lima <-shp.prov %>% dplyr::filter(prov=="LIMA"| prov=="CALLAO" )
rm(shp,shp.nac, shp.prov)
```
```{r, error=F, warning=F, echo=F, message=F}
vida_diaria <- data %>% dplyr::select(age,info_newspaper2,info_socialmedia2
,info_offiweb2
,info_tv2
,info_radio2
,info_null2
,lastphysical3
,food_diffic2
,time_child2
,play_child2
,homework_child2
,annoy_child2
,food2
,child_outhome2
)
salud_personal <- data %>% dplyr::select(income3,age,gender2,symp_fever2
,symp_headache2
,symp_sorethr2
,symp_taste2
,symp_smell2
,symp_nasalc2
,symp_drycough2
,symp_prodcough2
,symp_chest2
,symp_breath2
,symp_muscle2
,symp_weak2
,symp_nausea2
,symp_diarrea2
,symp_lossapet2
,symp_nosymp2
,symp_house3
,closecov_house2
,closecov_office2
,closecov_vehicle2
,closecov_nocont2
,closecov_unknown2
,covtest3
,testresult3
,testwhy3
,testwhen3
,risk2
,worry2
,smoke3
,b_heart2
,b_hyperten2
,b_diabetes2
,b_cancer2
,b_hiv2
,b_tb2
,b_asthma2
,b_obese2
,b_none2
,b_followup3
,nervanx3
,stopworry3
,littinter3
,sad3
,opinion3
,nobonus2
,ybonus_food2
,ybonus_fam2
,ybonus_pers2
,nomask_unknownget2
,nomask_uncomfy2
,nomask_noneed2
,satinitizer3
,avoidtouch3
)
```
```{r, error=F, warning=F, echo=F, message=F}
salud_personal$covtest <- relevel(salud_personal$covtest, "Si")
label(salud_personal$risk) <- "¿Cuál es el riesgo que ya tenga COVID-19 o que se infecte pronto?"
#label(salud_personal$symp_fever) <- "He tenido fiebre"
salud_personal$symp_fever <- relevel(salud_personal$symp_fever, "Si")
salud_personal$symp_headache <- relevel(salud_personal$symp_headache, "Si")
salud_personal$symp_sorethr <- relevel(salud_personal$symp_sorethr, "Si")
salud_personal$symp_taste <- relevel(salud_personal$symp_taste, "Si")
salud_personal$symp_smell <- relevel(salud_personal$symp_smell, "Si")
salud_personal$symp_nasalc <- relevel(salud_personal$symp_nasalc, "Si")
salud_personal$symp_drycough <- relevel(salud_personal$symp_drycough, "Si")
salud_personal$symp_prodcough <- relevel(salud_personal$symp_prodcough, "Si")
salud_personal$symp_chest <- relevel(salud_personal$symp_chest, "Si")
salud_personal$symp_breath <- relevel(salud_personal$symp_breath, "Si")
salud_personal$symp_muscle <- relevel(salud_personal$symp_muscle, "Si")
salud_personal$symp_weak <- relevel(salud_personal$symp_weak, "Si")
salud_personal$symp_nausea <- relevel(salud_personal$symp_nausea, "Si")
salud_personal$symp_diarrea <- relevel(salud_personal$symp_diarrea, "Si")
salud_personal$symp_lossapet <- relevel(salud_personal$symp_lossapet, "Si")
data$outhome3<- factor(data$outhome3, levels = c("Nunca","Una vez","Dos veces","Tres o más veces","Todos los días"))
```
Sociodemográfico {.bg}
=====================================
Column 1 {data-width=250}
-------------------------------------
### `r paste0('Encuestados de regiones y distritos no adscritos a Lima Metropolitana')`
```{r}
valueBox(paste0('1,041'),
icon = "fa-male",
color = '#a35fb8')
```
### `r paste0("Encuestados de Lima Metropolitana")`
```{r}
valueBox(paste0('2,378'),
icon = "fa-male",
color = '#a35fb8')
```
### Resumen
#### The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Column 2 {.tabset }
-------------------------------------
### Características
```{r}
####################
### Pyramid Plot ###
####################
# Subset y arreglo de datos
cols <- c("#2864b4","#ffad26")
pyramid_data <- data %>%
dplyr::select(edad = age,
nm_sex = gender2) %>%
dplyr::filter(nm_sex!=3)
pyramid_data$nm_sex <- as.factor(pyramid_data$nm_sex)
pyramid_data <- pyramid_data %>%
dplyr::filter(!is.na(edad)) %>%
dplyr::mutate(Hombre = if_else(as.integer(nm_sex)==2,1,0),
Mujer = if_else(as.integer(nm_sex)==1,1,0)) %>%
group_by(edad) %>%
dplyr::summarise(Hombre = sum(Hombre),Mujer = sum(Mujer)) %>%
dplyr::mutate(edad = if_else(edad>=18 & edad<25,"18 a 24",
if_else(edad>=25 & edad<35,"25 a 34",
if_else(edad>=35 & edad<45,"35 a 44",
if_else(edad>=45 & edad<55,"45 a 54",
if_else(edad>=55 & edad<65,"55 a 65",
if_else(edad>=65 & edad<75,"65 a 74",
if_else(edad>=75,"75 o +","ERROR"))))))))
pyramid_data$edad <- factor(pyramid_data$edad,
levels = pyramid_data$edad,
labels =pyramid_data$edad)
# Grafico de piramide poblacional (edad y sexo)
ggplot(pyramid_data) +
geom_bar(aes(x=edad, y=Mujer, fill="Mujer"), stat="identity") +
geom_bar(aes(x=edad, y=-Hombre, fill="Hombre"), stat="identity") +
coord_flip() +
theme_minimal() +
labs(title = "Información demográfica",
x = "Grupos de edad",
y = "",
color = "Sexo") +
scale_fill_manual(values= cols,
name="")+
scale_y_continuous(limits = c(-600,600),
breaks = seq(-600, 600, 100),
labels = paste0(as.character(c(seq(600, 0, -100), seq(100, 600, 100))))) +
theme(
plot.title = element_text(hjust = 0.5,
face="bold",
size=18),
axis.title.y = element_text(
size=14),
axis.text=element_text(size=12),
legend.title = element_text(face = "bold"),
legend.position="bottom",
legend.text=element_text(size=10),
panel.grid.major = element_blank(), panel.grid.minor = element_blank())
```
Column 3 {.tabset data-width=350}
-------------------------------------
### Perú
```{r, class.output="scroll-100", error=F, warning=F, echo=F, message=F, fig.height=10}
data.shp.nac %>% group_by(reg) %>% dplyr::summarise(n=n()) %>%
ggplot() +
geom_sf(aes(fill=n))+
scale_fill_gradient(name = "",
trans = scales::pseudo_log_trans(sigma = 100),
limits=c(0,250),
high="#ffad26", low="#ebebeb",
breaks=breaks_nac, labels=breaks_nac#,
#guide = "legend"
)+
theme_minimal() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank(),
axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank(),
plot.margin = margin(0,0,0,0),
legend.position=c(0.8,0.9),
legend.text= element_text(size=15),
legend.direction = "horizontal",
legend.box.margin=margin(0,0,0,0),
) +
geom_sf(data= shapefile_prov_lima,fill="Black") +
theme(legend.key.size = unit(0.75, "cm"))
```
### Lima Metropolitana
```{r, fig.height=10}
data.shp.lima %>% group_by(distr) %>% dplyr::summarise(n=n()) %>%
ggplot() +
geom_sf(aes(fill=n))+
scale_fill_gradient(name = "",
trans = scales::pseudo_log_trans(sigma = 100),
limits=c(0,500),
high="#2864b4", low="#ebebeb",
breaks=my_breaks, labels=my_breaks#,
#guide = "legend"
)+
theme_minimal() +
theme(panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.title.x=element_blank(),axis.text.x=element_blank(),axis.ticks.x=element_blank(),
axis.title.y=element_blank(),axis.text.y=element_blank(),axis.ticks.y=element_blank(),
plot.margin = margin(0,0,0,0),
legend.position=c(0.8,0.9),
legend.text= element_text(size=15),
legend.direction = "horizontal",
legend.box.margin=margin(0,0,0,0),
)+ theme(legend.key.size = unit(0.75, "cm"))
```
Vida Diaria {data-orientation=rows}
=====================================
Column 1
-------------------------------------
### Resumen
#### The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
### Medios de información
```{r}
helperFunction <- function(x){
ifelse(x=="Si", 1,0)
}
info.df<- data %>% dplyr::select(`Periódico` = info_newspaper2,
`Webs\nOficiales` =info_offiweb2,
Radio =info_radio2,
`Redes\nSociales`=info_socialmedia2,
`Televisión`=info_tv2)%>%
mutate_if(is.factor, as.character) %>%
mutate_all(helperFunction) %>%
dplyr::summarise_all(sum,na.rm=T) %>%
gather(info, n, `Periódico`:`Televisión`, factor_key=TRUE) %>%
dplyr::mutate(n = n/nrow(data))
p.order <- info.df %>% arrange(desc(n)) %>% pull(info)
info.df.n<- info.df %>%
transform(info=factor(info,levels=p.order)) %>%
ggplot(aes(x=info, y=n, fill=info)) +
geom_bar(stat="identity")+theme_minimal() + scale_fill_manual(values =c("#2864b4","#a35fb8","#ef5996","#ff765f","#ffad26"))+
scale_y_continuous(labels = percent, limits=c(0,0.8)) +
theme(legend.position = "none") +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=23),
#axis.title.y = element_text(
# size=16),
axis.text=element_text(size=16),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "Fuentes y medios\nde información más frecuentados",
x = "",
y = "",
color = "")
gob.img <- readPNG("../Data/icons/gob.png")
gob.img <- rasterGrob(gob.img, interpolate=TRUE)
gob.pos <- info.df %>% filter(info=="Webs\nOficiales") %>% pull(n)
web.img <- readPNG("../Data/icons/domain.png")
web.img <- rasterGrob(web.img, interpolate=TRUE)
web.pos <- info.df %>% filter(info=="Redes\nSociales") %>% pull(n)
tv.img <- readPNG("../Data/icons/tv.png")
tv.img <- rasterGrob(tv.img, interpolate=TRUE)
tv.pos <- info.df %>% filter(info=="Televisión") %>% pull(n)
radio.img <- readPNG("../Data/icons/radio.png")
radio.img <- rasterGrob(radio.img, interpolate=TRUE)
radio.pos <- info.df %>% filter(info=="Radio") %>% pull(n)
news.img <- readPNG("../Data/icons/periodico.png")
news.img <- rasterGrob(news.img, interpolate=TRUE)
news.pos <- info.df %>% filter(info=="Periódico") %>% pull(n)
info.df.n <- info.df.n +
annotation_custom(gob.img,xmin=1+1,xmax=1-1, ymin=gob.pos+0.02, ymax=gob.pos+0.12)+
annotation_custom(tv.img,xmin=3+1,xmax=3-1, ymin=tv.pos+0.02, ymax=tv.pos+0.12)+
annotation_custom(radio.img,xmin=5+1,xmax=5-1, ymin=radio.pos+0.02, ymax=radio.pos+0.12)+
annotation_custom(news.img,xmin=4+1,xmax=4-1, ymin=news.pos+0.02, ymax=news.pos+0.12)+
annotation_custom(web.img,xmin=2+1,xmax=2-1, ymin=web.pos+0.02, ymax=web.pos+0.12) +
coord_flip()
info.df.n
```
### Uso de mascarilla
```{r}
mask.usage <- data %>%
group_by(mask3) %>%
dplyr::summarise(n = n()) %>%
dplyr::mutate(n_por = round(n/sum(n)*500),
mask3 = as.factor(ifelse(as.character(mask3)=="Si","Si usó mascarilla",
ifelse(as.character(mask3)=="No aplica (no salgo de casa)","No sale de casa","No usó mascarilla")
)))
mask.usage$mask3 <- relevel(mask.usage$mask3, "No usó mascarilla")
mask.pic <- mask.usage%>%
arrange(desc(n_por)) %>%
ggplot(aes(label = mask3, values = n_por)) +
geom_pictogram(n_rows = 25, aes(colour = mask3), flip = TRUE, make_proportional = F,
family = "FontAwesome", size =4) +
theme_clean() +
theme_enhance_waffle()+
scale_label_pictogram(
name = NULL,
values = c("male", "male", "male"),
labels = c("No usó mascarilla", "No sale de casa","Si usó mascarilla")
)+
scale_color_manual(
name = NULL,
values = c( "#ff765f", "#ffa600","#0e5871"),
labels = c("No usó mascarilla", "No sale de casa","Si usó mascarilla")
) +
labs(title="Uso de mascarilla\nal salir de casa",
subtitle="1 en 342 participantes reportó no usar mascarilla al salir",
caption="*Representadas 499 personas"
) +
theme(legend.key.height = unit(2.25, "line")) +
theme(plot.margin = unit(c(0,0,0,0), "cm"),
plot.title = element_text(size=23,hjust = 0.5, vjust=0,face="bold"),
plot.subtitle = element_text(hjust = 0.5))
mask.pic
```
### Niños fuera de casa
```{r}
data %>%
filter(!is.na(child_outhome2)) %>%
group_by(child_outhome2) %>%
dplyr::summarise(n=n()) %>%
ungroup() %>% mutate(n=round(n/nrow(data %>%
filter(!is.na(child_outhome2)))*100, digits = 2)) %>%
ggplot(aes(x="", y=n, fill=child_outhome2))+
geom_bar(width = 1, stat = "identity")+
coord_polar("y", start=0)+
theme_clean() +
theme(axis.text.x=element_blank(),
plot.margin = unit(c(0,0,0,0), "cm"),
plot.title = element_text(size=23,hjust = 0.5, vjust=0,face="bold")) +
labs(title="¿Los niños salieron de casa\nen la última semana?",
subtitle="",
caption="*Total de respuestas: 1535",
fill="Respuesta:"
)+ scale_fill_manual(values=c("#ffad26","#2864b4")) +
geom_text(aes(y = n-10,
label = n,
size=30),
show.legend = FALSE
)
```
Column 2 {.tabset}
-------------------------------------
### Destinos
```{r, fig.width=15}
alluvial_plot<-data %>% dplyr::select(outhome3,
`Mercados y/o Supermercados`=place_markets_supermarkets,
`Hospital`=place_hospital2,
`Farmacia`=place_Farmacy2,
`Banco`=place_bank2,
`Trabajo`=place_work2,
`Visitas`=place_visit2,
`Paseos`=place_walkexe2,
Otros = place_other_mix2)%>%
group_by(outhome3)%>%
mutate_if(is.factor, as.character) %>%
mutate_all(helperFunction) %>%
dplyr::summarise_all(sum,na.rm=T) %>%
gather(place, n, `Mercados y/o Supermercados`:Otros, factor_key=TRUE) %>%
filter(n!=0)
p.order.place<- alluvial_plot %>% group_by(place) %>%dplyr::mutate(n=sum(n)) %>% arrange(desc(n)) %>% pull(place) %>% unique(.)
alluvial_plot<-alluvial_plot %>%
dplyr::mutate(place = factor(place,levels=p.order.place,labels = p.order.place))
#is_alluvia_form(alluvial_plot)
alluvial_plot_plot <- ggplot(alluvial_plot,
aes(y=n,axis1=place,axis2=outhome3)) +
geom_alluvium(aes(fill=outhome3),width=1/20) +
geom_stratum(width=1/9)+
geom_text(size=5,stat="stratum",aes(label=after_stat(stratum)))+
scale_x_discrete(limits=c("Número de salidas","Destino"),expand=c(.1,.1))+
theme_minimal() +
theme(legend.position = "right") +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=26),
plot.subtitle = element_text(hjust = 0.5,
size=22),
axis.title.y = element_text(
size=22,
hjust = 0.5),
axis.title.x = element_text(
size=22),
axis.text=element_text(size=14),
axis.text.y = element_blank(),
axis.text.x = element_blank(),
panel.grid.major = element_blank(), panel.grid.minor = element_blank()#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "Lugares de movilización",
subtitle= "¿Cuántas veces?",
y = "¿A dónde?",
fill = "") +
coord_flip() +
scale_fill_manual(values = c("#2864b4","#a35fb8","#ef5996","#ff765f","#ffad26")) +
theme(legend.position = "none")
alluvial_plot_plot
```
Vida Profesional {data-orientation=rows}
=====================================
Column 1
-------------------------------------
### Resumen
#### The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
### Estado ocupacional
```{r}
df_house_comp <- data %>%
select(work_before2,income3,work_change3,outhome3) %>%
mutate(income = as.factor(income3),
work_change = as.factor(work_change3))
df_house_comp$work_change <- revalue(df_house_comp$work_change, c("No, me he mantenido en la misma ocupación"="Sin cambios"))
df_house_comp$work_change <- revalue(df_house_comp$work_change, c("Si, antes estudiaba"="Antes estudiaba"))
df_house_comp$work_change <- revalue(df_house_comp$work_change, c("Si, antes trabajaba"="Antes trabajaba"))
df_house_comp$work_change <- revalue(df_house_comp$work_change, c("Si, antes estudiaba y trabajaba"="Antes estudiaba\ny trabajaba"))
df_house_comp$income <- revalue(df_house_comp$income, c("S/12,660 o más"="S/12,660\no más"))
df_house_comp$income <- revalue(df_house_comp$income, c("S/1,300 o menos"="S/1,300\no menos"))
df_house_comp$income <- factor(df_house_comp$income, levels = c("S/1,300\no menos","S/2,480", "S/3,970","S/7,020","S/12,660\no más"))
df_house_comp$work_change <- factor(df_house_comp$work_change, levels = c("Sin cambios", "Antes estudiaba", "Antes trabajaba","Antes estudiaba\ny trabajaba"))
df_house_comp %>% group_by(income,work_change) %>% dplyr::summarise(n=n())%>% ungroup()%>%
ggplot(aes(x=income, y=n, fill=work_change)) +
geom_bar(stat="identity",position="fill")+
scale_fill_manual(values = c("#2864b4","#c05bb0","#ff6872","#ffad26")) +
scale_y_continuous(labels = percent)+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "Cambios de ocupación por la pandemia\nsegún ingreso familiar",
subtitle="",
x = "Ingreso familiar promedio",
y = "",
fill = "Cambios de ocupación")
```
### Salidas fuera del hogar
```{r}
df_house_comp %>% select(outhome3,income) %>%
group_by(income,outhome3) %>%
dplyr::summarise(n=n()) %>% ungroup()%>%
ggplot(aes(x=income, y=n, fill=outhome3)) +
geom_bar(stat="identity",position="fill")+
scale_fill_manual(values = c("#2864b4","#a35fb8","#ef5996","#ff765f","#ffad26")) +
scale_y_continuous(label=percent)+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "Número de salidas por semana\nsegún ingreso familiar",
subtitle="",
x = "Ingreso familiar promedio",
y = "",
fill = "¿Cuantas veces salió\nde casa?")
```
Column 2
-------------------------------------
### Medidas de protección
```{r, fig.width=20}
data$whealth_stayhome2 <- relevel(data$whealth_stayhome2, "Si")
data$whealth_mask2 <- relevel(data$whealth_mask2, "Si")
data$whealth_respirator2 <- relevel(data$whealth_respirator2, "Si")
data$whealth_gloves2 <- relevel(data$whealth_gloves2, "Si")
data$whealth_face2 <- relevel(data$whealth_face2, "Si")
data$whealth_apron2 <- relevel(data$whealth_apron2, "Si")
data$whealth_none2 <- relevel(data$whealth_none2, "Si")
a <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_stayhome2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_stayhome2, y=n, fill=whealth_stayhome2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Permaneció en casa",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
b <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_mask2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_mask2, y=n, fill=whealth_mask2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Le proporcionaron una\nmascarilla quirúrgica",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
c <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_respirator2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_respirator2, y=n, fill=whealth_respirator2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Le proporcionaron un\nrespirador (N95, KN95, etc.)",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
d <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_gloves2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_gloves2, y=n, fill=whealth_gloves2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Le proporcionaron\nguantes",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
e <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_face2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_face2, y=n, fill=whealth_face2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Le proporcionaron\nprotector facial",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
f <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(whealth_apron2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=whealth_apron2, y=n, fill=whealth_apron2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="Le proporcionaron\nmandil",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=12),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2250))
ggarrange(a, b, c,d,e,f,
ncol = 6, nrow = 1) %>%
annotate_figure(top = text_grob("Medidas de protección entregadas por centros laborales\n(opción múltiple)", face="bold",size = 18),
bottom = text_grob("Total de personas que respondieron estas preguntas: 2,343", face = "italic", size = 8)
)
```
Prevención {data-orientation=rows}
=====================================
Column 1
-------------------------------------
### Resumen
#### The standard Lorem Ipsum passage, used since the 1500s
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
### Percepción del riesgo
```{r, error=F, warning=F, echo=F, message=F}
stay_home_age <-data %>% dplyr::select(age,risk2) %>% filter(!is.na(risk2)) %>%
dplyr::mutate(risk2 = ifelse(risk2=="Muy poco o riesgo nulo","Muy Poco o nulo\nRiesgo",
ifelse(risk2=="Poco riesgo","Poco\nRiesgo",
ifelse(risk2=="Mediano riesgo","Mediano\nRiesgo",
ifelse(risk2=="Alto riesgo","Alto\nRiesgo",
ifelse(risk2=="Muy alto riesgo","Muy Alto\nRiesgo","error"
)) )))) %>%
ggplot(aes(x=risk2,y=age)) +
geom_violin()+ stat_summary(fun.data=mean_sdl, mult=1,
geom="pointrange", color="red") +
coord_flip()
stay_home_age <-data %>% dplyr::select(age,risk2) %>% filter(!is.na(risk2)) %>%
dplyr::mutate(risk2 = ifelse(risk2=="Muy poco o riesgo nulo","Muy Poco o nulo\nRiesgo",
ifelse(risk2=="Poco riesgo","Poco\nRiesgo",
ifelse(risk2=="Mediano riesgo","Mediano\nRiesgo",
ifelse(risk2=="Alto riesgo","Alto\nRiesgo",
ifelse(risk2=="Muy alto riesgo","Muy Alto\nRiesgo","error"
)) ))),
risk2 = factor(risk2,levels = c("Muy Poco o nulo\nRiesgo","Poco\nRiesgo","Mediano\nRiesgo","Alto\nRiesgo","Muy Alto\nRiesgo"))) %>%
ggplot(aes(x=risk2,y=age)) +
geom_violin(aes(fill=risk2, alpha=1.5))+
scale_fill_manual(values = c("#2864b4","#a35fb8","#ef5996","#ff765f","#ffad26")) +
scale_y_continuous(breaks=c(20,40,60,80))+
theme_clean() +
theme(legend.position = "none") +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "",
subtitle="¿Cuál es el riesgo que ya tenga COVID-19\no que se infecte pronto?",
x = "",
y = "Edad",
fill = "") +
geom_boxplot(fill=NA,width=0.4, color="#f1f1f1")
stay_home_age
```
### Preocupación sobre su salud
```{r}
stay_home_age <- data %>% dplyr::select(age,worry2) %>% filter(!is.na(worry2)) %>%
dplyr::mutate(worry2 = ifelse(worry2=="Nada preocupado","Nada\nPreocupado",
ifelse(worry2=="Un poco preocupado","Un poco\npreocupado",
ifelse(worry2=="Moderadamente preocupado","Moderadamente\nPreocupado",
ifelse(worry2=="Muy preocupado","Muy\nPreocupado",
ifelse(worry2=="Extremadamente preocupado","Extremadamente\nPreocupado","error"
)) ))),
worry2 = factor(worry2,levels = c("Nada\nPreocupado","Un poco\npreocupado","Moderadamente\nPreocupado",
"Muy\nPreocupado","Extremadamente\nPreocupado"))) %>%
filter(!is.na(worry2)) %>%
ggplot(aes(x=worry2,y=age)) +
geom_violin(aes(fill=worry2, alpha=0.98))+
scale_fill_manual(values = c("#2864b4","#a35fb8","#ef5996","#ff765f","#ffad26")) +
scale_y_continuous(breaks=c(20,40,60,80))+
theme_clean() +
theme(legend.position = "none") +
theme(plot.title = element_text(hjust = 0.5,
face="bold",
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
labs(title = "",
subtitle="¿Cuán preocupado ha estado por su salud\ndurante la última semana?",
x = "",
y = "Edad",
fill = "") +
geom_boxplot(fill=NA,width=0.4, color="#f1f1f1")
stay_home_age
```
Column 2
-------------------------------------
### Medidas de protección personal
```{r, fig.width=20}
data$mask_crowdedplace2 <- relevel(data$mask_crowdedplace2, "Si")
data$mask_work2 <- relevel(data$mask_work2, "Si")
data$mask_pubtransp2 <- relevel(data$mask_pubtransp2, "Si")
data$mask_alltime2 <- relevel(data$mask_alltime2, "Si")
data$mask_home2 <- relevel(data$mask_home2, "Si")
a <- data %>% filter(as.character(mask3) =="Si") %>%
group_by(mask_crowdedplace2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=mask_crowdedplace2, y=n, fill=mask_crowdedplace2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="En lugares conglomerados",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2500))
b <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(mask_work2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=mask_work2, y=n, fill=mask_work2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="En el trabajo",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2500))
c <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(mask_pubtransp2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=mask_pubtransp2, y=n, fill=mask_pubtransp2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="En el transporte público",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2500))
d <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(mask_alltime2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=mask_alltime2, y=n, fill=mask_alltime2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="En todo momento,\ncuando salgo de casa",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2500))
e <- data %>% filter(as.character(whealth_na2) =="No") %>%
group_by(mask_home2) %>%
dplyr::summarise(n=n()) %>%
ggplot(aes(x=mask_home2, y=n, fill=mask_home2)) +
geom_bar(stat="identity")+theme_minimal()+
labs(title="En todo momento,\nincluso dentro de casa",
subtitle="",
caption="",
fill="Respuesta:",
x="",
y=""
)+ scale_fill_manual(values=c("#ffad26","#2864b4"))+
theme_clean() +
theme(plot.title = element_text(hjust = 0.5,
size=16),
plot.subtitle = element_text(hjust = 0.5,
size=14),
axis.title.y = element_text(
size=14),
axis.title.x = element_text(
size=14),
axis.text=element_text(size=10)#,
#legend.title = element_text(face = "bold"),
#legend.position="bottom",
#legend.text=element_text(size=16)
)+
theme(legend.position = "none")+
scale_y_continuous(limits=c(0, 2500))
ggarrange(a, b, c,d,e,
ncol = 5, nrow = 1) %>%
annotate_figure(top = text_grob("¿Cúando y dónde utiliza las mascarillas?\n(opción múltiple)", face="bold",size = 18),
bottom = text_grob("Total de personas que respondieron estas preguntas: 3,134", face = "italic", size = 8)
)
```